import request from '@/utils/request';

// 地理编码（地址转坐标）
export function geocode(address: string, city?: string) {
  return request({
    url: '/map/map/geocode',
    method: 'get',
    params: { address, city }
  });
}

// 逆地理编码（坐标转地址）
export function regeocode(longitude: number, latitude: number) {
  return request({
    url: '/map/map/regeocode',
    method: 'get',
    params: { longitude, latitude }
  });
}

// 计算两点之间的距离
export function calculateDistance(fromLongitude: number, fromLatitude: number, toLongitude: number, toLatitude: number) {
  return request({
    url: '/map/map/distance',
    method: 'get',
    params: { fromLongitude, fromLatitude, toLongitude, toLatitude }
  });
}

// 获取行政区划信息
export function getDistricts(keywords: string, subdistrict: number = 1) {
  return request({
    url: '/map/map/districts',
    method: 'get',
    params: { keywords, subdistrict }
  });
}

// 获取周边搜索
export function searchAround(longitude: number, latitude: number, keywords: string, radius: number = 1000) {
  return request({
    url: '/map/map/around',
    method: 'get',
    params: { longitude, latitude, keywords, radius }
  });
}

// 步行路线规划
export function planWalkingRoute(fromLongitude: number, fromLatitude: number, toLongitude: number, toLatitude: number) {
  return request({
    url: '/map/map/walking',
    method: 'get',
    params: { fromLongitude, fromLatitude, toLongitude, toLatitude }
  });
}

// 获取IP地址
export function getIp() {
  return request({
    url: '/map/map/getIP',
    method: 'get'
  });
}

// 根据IP获取位置信息
export function getLocationByIp(ip: string) {
  return request({
    url: '/map/map/ip',
    method: 'get',
    params: { ip }
  });
}
